using System;
using System.Collections.Generic;
using System.Text;
using Blazing.BusinessObjects.Cms;
using Blazing.BusinessObjects.Queries;
using Blazing.WebFacade.Extensions;

using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using ClassInitialize = NUnit.Framework.TestFixtureSetUpAttribute;
using ClassCleanup = NUnit.Framework.TestFixtureTearDownAttribute;

namespace BusinessObjectTests
{
    [TestClass]
    public class SiteTests : NHibernateInMemoryTestFixtureBase
    {
        private void CheckValues(Site obj, Site newObj)
        {
            Assert.AreEqual(obj.ID, newObj.ID);
            Assert.AreEqual(obj.Name, newObj.Name);
            Assert.AreEqual(obj.Url, newObj.Url);
            //Assert.AreEqual(obj.ImageType.ID, newObj.ImageType.ID);
            Assert.AreEqual(obj.IsLoginRequired, newObj.IsLoginRequired);
            Assert.AreEqual(obj.RowStamp, newObj.RowStamp);
        }

        [TestMethod]
        public void CreateSite()
        {
            Site obj = BusinessObjectFactory.CreateAndFillSite();

            obj.Save();

            Site obj2 = Site.Load(obj.ID);

            Assert.IsNotNull(obj2);

            CheckValues(obj, obj2);

            obj.Delete();
            obj.Save();
        }

        [TestMethod]
        public void LoadSiteByAlias()
        {
            Site obj = BusinessObjectFactory.CreateAndFillSite();
            obj.Aliases.Add(new SiteAlias { Name = "Test", Url = "localhost", ParentSite = obj });
            obj.SetSession(session);
            obj.Save();

            IList<Site> sites = Site.Search(QrySearchSites.Query("localhost"));
            Assert.AreEqual(obj.ID, sites[0].ID);
        }

        [TestMethod]
        public void LoadSiteByAliasAndUri()
        {
            Site obj = BusinessObjectFactory.CreateAndFillSite();
            obj.Aliases.Add(new SiteAlias { Name = "Test", Url = "localhost", ParentSite = obj });
            obj.SetSession(session);
            obj.Save();

            Uri u = new Uri("http://localhost");
            Site s = u.GetSite();

            Assert.AreEqual(obj.ID, s.ID);
        }
    }
}
